<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="训练前(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xlq" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m即刻(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xljk" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 20min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl20" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 40min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl40" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 60min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl60" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 80min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl80" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 100min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl100" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 120min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl120" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 140min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl140" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 160min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl160" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 180min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl180" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 200min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl200" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 220min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl220" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 240min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl240" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 260min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl260" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 280min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl280" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 300min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl300" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 320min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl320" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 340min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl340" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="7500m 360min(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xl360" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="训练后(血氧饱和|心率|呼吸|血压)">
            <el-input v-model="form.xlh" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="主观症状(症状id1|症状id2|...)">
            <el-input v-model="form.feels" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="结果判定">
            <el-input v-model="form.result" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="建议">
            <el-input v-model="form.jy" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="记录日期">
            <el-input v-model="form.date" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="记录人">
            <el-input v-model="form.createBy" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="xlq" label="训练前(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xljk" label="7500m即刻(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl20" label="7500m 20min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl40" label="7500m 40min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl60" label="7500m 60min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl80" label="7500m 80min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl100" label="7500m 100min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl120" label="7500m 120min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl140" label="7500m 140min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl160" label="7500m 160min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl180" label="7500m 180min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl200" label="7500m 200min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl220" label="7500m 220min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl240" label="7500m 240min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl260" label="7500m 260min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl280" label="7500m 280min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl300" label="7500m 300min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl320" label="7500m 320min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl340" label="7500m 340min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xl360" label="7500m 360min(血氧饱和|心率|呼吸|血压)" />
        <el-table-column prop="xlh" label="训练后(血氧饱和|心率|呼吸|血压)" />
        <el-table-column label="主观症状">
          <template slot-scope="scope">
            {{ getFeelNamesFromString(scope.row.feels) }}
          </template>
        </el-table-column>
        <el-table-column prop="result" label="结果判定" />
        <el-table-column prop="jy" label="建议" />
        <el-table-column prop="date" label="记录日期" />
        <el-table-column prop="createBy" label="记录人" />
        <el-table-column v-if="checkPer(['admin','trainQyty:edit','trainQyty:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudTrainQyty from '@/api/trainQyty'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import { convertFeelsToString } from '@/utils/feel'

const defaultForm = { id: null, trainId: null, xlq: null, xljk: null, xl20: null, xl40: null, xl60: null, xl80: null, xl100: null, xl120: null, xl140: null, xl160: null, xl180: null, xl200: null, xl220: null, xl240: null, xl260: null, xl280: null, xl300: null, xl320: null, xl340: null, xl360: null, xlh: null, feels: null, result: null, jy: null, date: null, createBy: null, trainItemId: null }
export default {
  name: 'TrainQyty',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '缺氧体验训练', url: 'api/trainQyty', idField: 'id', sort: 'id,desc', crudMethod: { ...crudTrainQyty }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'trainQyty:add'],
        edit: ['admin', 'trainQyty:edit'],
        del: ['admin', 'trainQyty:del']
      },
      rules: {
      }
    }
  },
  methods: {
    // 将感受字符串转换为名称
    getFeelNamesFromString(feelsString) {
      return convertFeelsToString(feelsString)
    },
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
